/*
 * Copyright (C) 2024 ~ 2025 Deepin Technology Co., Ltd.
 *
 * Author:     zhangbingyi <zhangbingyi@uniontech.com>
 *
 * Maintainer: zhangbingyi <zhangbingyi@uniontech.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "cleanermodule.h"
#include "trashcleanwidget.h"
#include "cleanerdbusadaptorimpl.h"

#include <QModelIndex>
#include <QStandardItemModel>

CleanerModule::CleanerModule(FrameProxyInterface *frameProxy, QObject *parent)
    : QObject(parent)
    , ModuleInterface(/*frameProxy*/)
    , m_dbusAdaptorImpl(nullptr)
    , m_widget(nullptr)
{
}

CleanerModule::~CleanerModule()
{
    // 在m_frameProxy->pushWidget方法调用中，已经将显示页的父指针指向MainWindow对象，各显示页是否释放由MainWindow对象决定
    // 所以此处不能手动删除各显示页
}

void CleanerModule::initialize()
{
}

void CleanerModule::preInitialize()
{
}

const QString CleanerModule::name() const
{
    return MODULE_DISK_CLEANER_NAME;
}

void CleanerModule::active(int index)
{
    Q_UNUSED(index);
    if (!m_dbusAdaptorImpl) {
        m_dbusAdaptorImpl = new CleanerDBusAdaptorImpl(this);
    }

    if (nullptr == m_widget) {
        m_widget = new TrashCleanWidget(nullptr, m_dbusAdaptorImpl);
    }

//    connect(m_widget, &QWidget::destroyed, this, [&] {
//        m_widget = nullptr;
//    });

    m_widget->show();
//    m_frameProxy->pushWidget(this, m_widget);
}

void CleanerModule::deactive()
{
}
